<?php $aOptionChuyenCan = array_merge($Option['LE'], $Option['HOC']); ?>
<table class="table table-bordered table-hover">
    <thead>
        <tr>
            <th rowspan="2" style="vertical-align: middle" class="fixed-column">
                {{ trans('user.username') }}
            </th>
            @foreach($aChuyenCanHeader as $date)
            <th colspan="2" class="text-center">{{{ CNamHoa::ConvertDate($date) }}}</th>
            @endforeach
            <th rowspan="2"></th>
            @foreach($aHocLucHeader as $Object)
            <th colspan="{{count($Option['LAN_KIEM_TRA'])}}" class="text-center">
                {{ $Option['DOT_KIEM_TRA'][$Object]->data or $Object }}
            </th>
            @endforeach
            <th rowspan="2"></th>
            <th colspan="{{count($aOptionChuyenCan) + 2}}" class="text-center">
                {{ trans('navigation.mornitor.attendance') }}
            </th>
            <th rowspan="2"></th>
            <th colspan="2" class="text-center">
                {{ trans('navigation.mornitor.score') }}
            </th>
            <th rowspan="2"></th>
            <th rowspan="2" class="text-center" style="vertical-align: middle">
                {{trans('review.rank')}}
            </th>
        </tr>
        <tr>
            @foreach($aChuyenCanHeader as $date)
            <th class="text-center">
                {{ trans('options.LE') }}
            </th>
            <th class="text-center">
                {{ trans('options.HOC') }}
            </th>
            @endforeach


            @foreach($aHocLucHeader as $Object)
            @foreach($Option['LAN_KIEM_TRA'] as $Objectj)
            <th class="text-center">
                {{ $Objectj->data }}
            </th>
            @endforeach
            @endforeach


            @foreach($aOptionChuyenCan as $Info)
            <th class="text-center">
                {{ $Info->data->name }}
            </th>
            @endforeach
            <th class="text-center">{{trans('review.average')}}</th>
            <th class="text-center">{{trans('review.rank')}}</th>


            <th class="text-center">{{trans('review.average')}}</th>
            <th class="text-center">{{trans('review.rank')}}</th>
        </tr>
    </thead>
    <tbody>
        @foreach($aUser as $User)
        {{--*/
        $counterTicket = [];
        /*--}}
        <tr>
            <td class="no-wrap">{{{ $User->username }}}</td>
            @foreach($aChuyenCanHeader as $date)
            <td class="no-wrap">
                {{--*/
                $ticket = @$aUserChuyenCan[$User->id][$date]['LE'] or '';
                @$counterTicket[$ticket] ++;
                $ticket = @$Option['LE'][$ticket]->data->name or $ticket;
                /*--}}
                <div class="tooltips" data-original-title="{{{$User->username}}}" data-placement="top">
                    {{ $ticket }}&nbsp;
                </div>
            </td>
            <td class="no-wrap">
                {{--*/
                $ticket = @$aUserChuyenCan[$User->id][$date]['HOC'] or '';
                @$counterTicket[$ticket] ++;
                $ticket = @$Option['LE'][$ticket]->data->name or $ticket;
                /*--}}
                <div class="tooltips" data-original-title="{{{$User->username}}}" data-placement="top">
                    {{ $ticket }}&nbsp;
                </div>
            </td>
            @endforeach

            <td class="no-wrap"></td>

            @foreach($aHocLucHeader as $key)
            {{--*/
            $keyName = @$Option['DOT_KIEM_TRA'][$key]->data or $key;
            /*--}}
            @foreach($Option['LAN_KIEM_TRA'] as $key1)
            {{--*/
            $item = @$aUserHocLuc[$User->id][$key][$key1->key] or '';
            /*--}}
            <td class="no-wrap">
                <div class="text-center tooltips" data-original-title="{{{$User->username}}} {{{$keyName}}} {{{$Objectj->data}}}" data-placement="top">
                    {{{ $item }}}&nbsp;
                </div>
            </td>
            @endforeach
            @endforeach

            <td></td>

            @foreach($aOptionChuyenCan as $key => $Info)
            <td class="text-center no-wrap">
                <div class="tooltips" data-original-title="{{{$User->username}}}" data-placement="top">
                    @if(isset($counterTicket[$key]))
                    {{ $counterTicket[$key] }} | {{ $counterTicket[$key] * $Info->data->minus }} 
                    @else
                    &nbsp;
                    @endif
                </div>
            </td>
            @endforeach
            <td class="text-center no-wrap">
                <div class="tooltips" data-original-title="{{{$User->username}}}" data-placement="top">
                    {{(float)$User->pivot->chuyencan}}
                </div>
            </td>
            <td class="text-center no-wrap">
                <div class="tooltips" data-original-title="{{{$User->username}}}" data-placement="top">
                    {{ CNamHoa::getChuyenCanRank( (float)$User->pivot->chuyencan ) }}
                </div>
            </td>

            <td></td>

            <td class="text-center no-wrap">
                <div class="tooltips" data-original-title="{{{$User->username}}}" data-placement="top">
                    {{(float)$User->pivot->hocluc}}
                </div>
            </td>
            <td class="text-center no-wrap">
                <div class="tooltips" data-original-title="{{{$User->username}}}" data-placement="top">
                    {{ CNamHoa::getHocLucRank( (float)$User->pivot->hocluc ) }}
                </div>
            </td>

            <td></td>

            <td class="text-center btn-update no-wrap" user_id="{{$User->id}}" style="cursor: pointer">
                {{--*/
                $rank = $Option['RANK'][$User->pivot->rank]->data or $User->pivot->rank;
                /*--}}
                <div class="tooltips" data-original-title="{{{$User->username}}}" data-placement="left">
                    {{ $rank }}
                </div>
            </td>
        </tr>
        @endforeach
    </tbody>
</table>
<script type="text/javascript">
    jQuery('.tooltips').tooltip();

    $.fn.modal.defaults.spinner = $.fn.modalmanager.defaults.spinner =
            '<div class="loading-spinner" style="width: 200px; margin-left: -100px;">' +
            '<div class="progress progress-striped active">' +
            '<div class="progress-bar" style="width: 100%;"></div>' +
            '</div>' +
            '</div>';

    $.fn.modalmanager.defaults.resize = true;

    var $modal = $('#ajax-modal');

    $('table td.btn-update').click(function() {
        $('body').modalmanager('loading');

        var obj = {};
        obj['user_id'] = $(this).attr('user_id');
        obj['class_id'] = '{{$Classes->id}}';

        $modal.load('{{route("review-form")}}', obj, function() {
            $modal.modal().on("hidden", function() {
                $modal.empty();
            });

            $modal.find('.btn-updateReview').click(function() {

                var form = $('#form-review');
                var error = $('.alert-danger', form);
                var success = $('.alert-success', form);

                $.ajax({
                    url: form.attr('action'),
                    type: form.attr('method'),
                    data: form.serialize(),
                    dataType: 'json'
                }).done(function(response) {
                    if (response.status == 200) {

                        $('td[user_id="' + response.user_id + '"]')
                                .find('div').html(response.rank).end();

                        $('.btn-close-modal').click();
                    }
                    else {
                        error.find('span').text(response.message);
                        error.show();
                        success.hide();
                    }
                }).fail(function() {
                    error.find('span').text('Check Your Connection.');
                    error.show();
                    success.hide();
                });
            });
        }, 'json');
    });
</script>